#include <iostream>
#include <functional>
#include <pthread.h>
#include <string>
using namespace std;
template<class T>
using func_t = function<void(T)>;
using task_t=function<void(int)>;
template<class T>
class Phreadpack
{
public:
    Phreadpack(const string &name, func_t<T> func,T data)
        :_tid(0), _Phreadpackname(name), _runing(false),_func(func),_data(data)
    {
    }
    static void *PhreadRoutine(void *arg)
    {
        Phreadpack *ts = static_cast<Phreadpack *>(arg);
        ts->_func(ts->_data);
        return nullptr;
    }
    bool start()
    {
        //         task_t t=bind(&Phreadpack::Phreadname,this,3);
        // t(3);
        int n = pthread_create(&_tid, nullptr, PhreadRoutine, this /*?*/);
task_t t=bind(&Phreadpack::Phreadname,this,3);
        t(3);
        if (n == 0)
        {
            _runing = true;
            return true;
            //  _runing = true;
            // return true;
        }
        else return false;
    }
    bool join()
    {
        if (!_runing)
            return true;
        int n = pthread_join(_tid, nullptr);
        if (n == 0)
        {
            _runing = false;
            return true;
        }
        else
            return false;
    }
    string Phreadname(int a)
    {
        cout<<_tid<<":"<<"你好"<<endl;
        return _Phreadpackname;
    }
    bool isrunning()
    {
        return _runing;
    }
    ~Phreadpack()
    {
    }
    string _Phreadpackname;
     T _data;
    pthread_t _tid;
    bool _runing;
    func_t<T> _func;
};
